<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with pixels[] - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=pixels%5B%5D</link>
      <pubDate>Sun, 08 Aug 2021 15:27:50 +0000</pubDate>
         <description>Tagged with pixels[] - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedpixels%5B%5D/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Pixel Sort video</title>
      <link>https://forum.processing.org/two/discussion/25288/pixel-sort-video</link>
      <pubDate>Wed, 29 Nov 2017 23:04:47 +0000</pubDate>
      <dc:creator>Alment</dc:creator>
      <guid isPermaLink="false">25288@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>I'm new to processing but have been trying to pick it up lately.  I am a painter and know next to nothing about code but I did successfully use a code this month to write video to LEDs.  I am now really interested in the possibility of being able to abstract a video by assigning pixels to certain areas of a screen.  I'd like to be able to sort the pixels of each frame of a video by color so that each frame still contains its original pixels but not in their original order.  Any chance theres a code that will somehow do this for me out there? :)</p>

<p>Currently trying to consult people in the engineering school of my university but they're not very familiar with processing.</p>

<p>Anything would help, thanks !!</p>
]]></description>
   </item>
   <item>
      <title>Drawing a rectangle without using rects();</title>
      <link>https://forum.processing.org/two/discussion/25266/drawing-a-rectangle-without-using-rects</link>
      <pubDate>Wed, 29 Nov 2017 09:28:29 +0000</pubDate>
      <dc:creator>misus</dc:creator>
      <guid isPermaLink="false">25266@/two/discussions</guid>
      <description><![CDATA[<p>Hey everyone!
I really need help with this task. I need to draw a rectangle without using the function rect() but by creating my own function, which I've been trying to do but it just doesn't work. Could anyone help me with this please? 
This is my code:</p>

<pre><code>PImage img;
color c = color(random(255), random(255), random(255));

void setup() { 
  size(400, 400);
  img = createImage(400, 400, RGB); 
  img.loadPixels();
  img.updatePixels();
  image(img, 0, 0);
}

void draw() {
  myRectangle(10, 10, 40, 50);
}

void myRectangle(int xPos, int yPos, int widthRect, int heightRect) {
  img.loadPixels();
  for (int y = yPos; y &lt; yPos + heightRect; y++) {
    for (int x = yPos; x &lt; xPos + widthRect; x++) {
      img.set(y*width, x, c);
    }
  }
  img.updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>get color average from picture parts and save values in an array to send via serial</title>
      <link>https://forum.processing.org/two/discussion/25302/get-color-average-from-picture-parts-and-save-values-in-an-array-to-send-via-serial</link>
      <pubDate>Thu, 30 Nov 2017 13:54:10 +0000</pubDate>
      <dc:creator>waldooo</dc:creator>
      <guid isPermaLink="false">25302@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I am using part of a code I've found here in the forum ( <a rel="nofollow" href="https://forum.processing.org/two/discussion/15573/get-the-average-rgb-from-pixels">Get the average RGB from pixels</a> from <a rel="nofollow" href="https://forum.processing.org/two/profile/287/bourdonprince">bourdonprince</a> and <a rel="nofollow" href="https://forum.processing.org/two/profile/56/GoToLoop">GoToLoop</a>) that gets the color average values and display squares like big pixels on screen.</p>

<p><strong>Now I want to use this values to set the pixels colors of a RGB LED strip.</strong></p>

<p>The problem is that when I separate and read (at the processing console) de values of the color for each pixel, <strong>I get almost all my pixels with 0 for red...</strong> But the squares drawn in the screen seems OK, only the values I try to save to the matrix for latter use that seems odd.</p>

<p>Below is my code ( <em>with thanks to bourdonprince and GoToLoop</em>):</p>

<pre lang="java">
import processing.video.*;
Capture webcam;

import processing.serial.*;
Serial myPort;

float[][] rx;
float[][] gx;
float[][] bx;

void setup() {
  size(440, 320);

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  rx = new float[16][15];
  gx = new float[16][15];
  bx = new float[16][15];

  webcam = new Capture(this, 320, 240);  
  //String[] devices = Capture.list();
  //println(devices);
  webcam.start();
}

void draw() {

  if (webcam.available() == true) {
    webcam.read();
    image(webcam, 0, 0, width, height);
    saveFrame("/data/image.jpg");
  }

  delay(100);

  PImage img = loadImage("image.jpg");
  int detail = 30; // tamanho do quadrado

  int count_i = 0;
  int count_j = 0;


  for (int j=0; j&lt; height; j+=detail) {
    
    count_i = 0;

    for (int i=0; i &lt; width; i+=detail) {
      PImage newImg = img.get(i, j, detail, detail);
      noStroke();
      color cor = extractColorFromImage(newImg);
      fill(cor);
      rx[count_i][count_i]= red(cor);
      gx[count_i][count_j]= green(cor);
      bx[count_i][count_j]= blue(cor);

      count_i++;
    }
    count_j++;
  }


  for (int i=0; i&lt;15; i++)
  {
    for (int j=0; j&lt;11; j++)
    {
      println((i) + "," + (j) + "," + int( rx[i][j] )+ "," + int (gx[i][j]) + "," + int (bx[i][j]));
      //delay(100);
      myPort.write((i) + "," + (j) + "," + int( rx[i][j] )+ "," + int (gx[i][j]) + "," + int (bx[i][j])  + "\n");
      delay(50);
    }
  }

  delay(2000);
}



//função para extrair a cor média em um recorte
color extractColorFromImage(PImage img) {
  img.loadPixels();
  color r = 0, g = 0, b = 0;

  for (final color c : img.pixels) {
    r += c &gt;&gt; 020 &amp; 0xFF;
    g += c &gt;&gt; 010 &amp; 0xFF;
    b += c        &amp; 0xFF;
  }

  r /= img.pixels.length;
  g /= img.pixels.length;
  b /= img.pixels.length;

  return color(r, g, b);
}
</pre>
]]></description>
   </item>
   <item>
      <title>Kinect SimpleOpenNI</title>
      <link>https://forum.processing.org/two/discussion/13774/kinect-simpleopenni</link>
      <pubDate>Fri, 04 Dec 2015 13:59:39 +0000</pubDate>
      <dc:creator>phaidon</dc:creator>
      <guid isPermaLink="false">13774@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,I m trying to make this code with kinect,Im using as help guide the book "Makings things see" with SimpleOpenNI library in processing 2.2.1. I want get the data from the kinct and when i get into one specific area in front of kinect the pixels will get colorized.This is the first test of an aplication for children with Down Syndrome,I can make it wit user tracking because it will be awkard making them take a pose to calibrate. Thank You very much Here is the code:</p>

<p>``</p>

<p>import SimpleOpenNI.*;</p>

<p>SimpleOpenNI kinect;</p>

<p>int closestValue;
int closestX;
int closestY;
int Threshold;
int PixelsInFrame;</p>

<p>void setup() {</p>

<p>size(640, 480);
  kinect = new SimpleOpenNI(this);</p>

<p>kinect.enableDepth();
  //kinect.enableRGB();
}</p>

<p>void draw() {</p>

<p>closestValue =800;
  Threshold = 1000;</p>

<p>kinect.update();</p>

<p>int[] depthValues = kinect.depthMap();</p>

<p>//int currentDepthValue =</p>

<p>//PImage depthImage = kinect.depthImage();</p>

<p>// get the depth array from kinect</p>

<p>for (int y = 0; y &lt; 480; y++) {
    for (int x = 0; x &lt; 640; x++) {</p>

<pre><code>  int i = x + y *640;

  int currentDepthValues  = depthValues[i];


  //Find the pixels in certain distance bound)
  //fIND THE PIXELS IN Y AND X AXIS and paint them one colour
  //find the pixels and make them interact with other shapes

  if ( currentDepthValues &gt; 0 &amp;&amp; currentDepthValues &lt;= Threshold &amp;&amp; currentDepthValues &gt;= closestValue) {

  currentDepthValues = PixelsInFrame;

  print(PixelsInFrame);



    /*loadPixels();
     for (int k = 0; k &lt; depthValues[i].length; k++){
     pixels[k] = pink; 
     }

     updatePixels();*/


    //depthValues[i] = color(0, 255, 0);
  }
}
</code></pre>

<p>}</p>

<p>image(kinect.depthImage(), 0, 0);</p>

<p>}</p>

<p>``</p>
]]></description>
   </item>
   <item>
      <title>Strange things happen while trying to draw an average frame using a recursive formula.</title>
      <link>https://forum.processing.org/two/discussion/24955/strange-things-happen-while-trying-to-draw-an-average-frame-using-a-recursive-formula</link>
      <pubDate>Fri, 10 Nov 2017 19:23:32 +0000</pubDate>
      <dc:creator>Rakerson</dc:creator>
      <guid isPermaLink="false">24955@/two/discussions</guid>
      <description><![CDATA[<p>Hey !
I want to draw on a screen, an average frame using formula like this: aFrame = 0.99aFrame + 0.01CurrentFrame; (CurrentFrame is an actual frame taken from cam).
Ofcourse at the beginning "aFrame" contain diffrent value but with  each iteration (new frame loaded) it its closer to CurrentFrame value. After about 10-30 (considering we are using 30 fps camera and the image is static) aFrame should be equal to CurrentFrame and we should get picture like this:
<img src="" alt="" /><img src="https://forum.processing.org/two/uploads/imageupload/299/JPY568RN7PKT.JPG" alt="test1" title="test1" />
Instead, what I get is this:
<img src="https://forum.processing.org/two/uploads/imageupload/694/PIGHD5I1BMX7.JPG" alt="test2" title="test2" /></p>

<p>Here is a simple code. What is wrong with these calculations ? Why aren't the rc,gc,bc values getting closer to current frame values ?</p>

<pre><code>import processing.video.*; 
import processing.serial.*; 

Capture video;
Serial myPort; 

void setup() 
{
  size(640, 480);
  video = new Capture(this, width, height, 30);
  video.start();
}

void captureEvent(Capture video) 
{ 
  video.read(); 
}

void draw() 
{  
  video.loadPixels();
  image(video, 0, 0);

  loadPixels();

   float rc = 0; // Initialaizing values are 0, so at the start, strange thinks may display 
   float gc = 0; 
   float bc = 0;

  for (int x = 0; x &lt; video.width; x++ ) 
  {
    for (int y = 0; y &lt; video.height; y++ ) 
    {
      int loc = x + y * video.width;

      color currentColor = video.pixels[loc]; //current values, taken from cam
      float r3 = red(currentColor);
      float g3 = green(currentColor);
      float b3 = blue(currentColor);

      rc = rc*0.99 + r3*0.01;        //with each iterations, rc,gc,bc values are closer to current frame
      gc = gc*0.99 + g3*0.01;        //so after some time, these values will be almost equal to current r3, g3, b3
      bc = bc*0.99 + b3*0.01;

      pixels[loc] = color(rc,gc,bc); //I am drawing the values on screen, after some time, I should get clear a clear picture. 
    }
  }
  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Save frames of background subtraction capture</title>
      <link>https://forum.processing.org/two/discussion/24257/save-frames-of-background-subtraction-capture</link>
      <pubDate>Mon, 25 Sep 2017 22:21:55 +0000</pubDate>
      <dc:creator>iiyeo</dc:creator>
      <guid isPermaLink="false">24257@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I am doing a background subtraction capture demo recently but I met with difficulties. I have already get the pixel of silhouette extraction and I intend to draw it into a buffer through createGraphics(). I set the new background is 100% transparent so that I could only get the foreground extraction. Then I use saveFrame() function in order to get png file of each frame. However, it doesn't work as I expected.I intend to get a series of png of the silhouette extraction with 100% transparent background but now I only get the general png of frames from the camera feed.  Is there anyone could help me to see what's the problem with this code? Thanks a lot in advance. Any help will be appreciated.</p>

<pre><code>import processing.video.*;

Capture video;

PGraphics pg;

PImage backgroundImage;
float threshold = 30;

void setup() {
  size(320, 240);
  video = new Capture(this, width, height);
  video.start();

  backgroundImage = createImage(video.width, video.height, RGB); 
  pg = createGraphics(320, 240);
}

void captureEvent(Capture video) {
  video.read();
}

void draw() {
  pg.beginDraw();

  loadPixels();
  video.loadPixels();
  backgroundImage.loadPixels();

  image(video, 0, 0);
  for (int x = 0; x &lt; video.width; x++) {
    for (int y = 0; y &lt; video.height; y++) {
      int loc = x + y * video.width;



color fgColor = video.pixels[loc];
color bgColor = backgroundImage.pixels[loc];

float r1 = red(fgColor); float g1 = green(fgColor); float b1 = blue(fgColor);
float r2 = red(bgColor); float g2 = green(bgColor); float b2 = blue(bgColor);
float diff = dist(r1, g1, b1, r2, g2, b2);


if (diff &gt; threshold) {
  pixels[loc] = fgColor;
} else {
  pixels[loc] = color(0, 0);
}
    }}
    pg.updatePixels();
    pg.endDraw();


    saveFrame("line-######.png");
}


void mousePressed() {
  backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  backgroundImage.updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>color range checking</title>
      <link>https://forum.processing.org/two/discussion/24102/color-range-checking</link>
      <pubDate>Tue, 12 Sep 2017 16:58:13 +0000</pubDate>
      <dc:creator>jeffmarc</dc:creator>
      <guid isPermaLink="false">24102@/two/discussions</guid>
      <description><![CDATA[<p>I want to check if the returned value read from a gray level image ( 0-255) image is a graylevel and not a color.
I paint blob objects red with threshold filter and i want to skip over that red part.
SO...
if img.pixels[loc] &gt;&gt; 8 &amp; 0xFF is not a color then ...
Can i check the result for between 0,0,0 - 255,255,255 grayscale only , so a color of 0,255,0 would not be true?</p>

<p>still trying to understand what  the color values return and how to decipher them
thanks</p>
]]></description>
   </item>
   <item>
      <title>How to change loaded image alpha value in P5.js?</title>
      <link>https://forum.processing.org/two/discussion/23995/how-to-change-loaded-image-alpha-value-in-p5-js</link>
      <pubDate>Fri, 01 Sep 2017 14:27:52 +0000</pubDate>
      <dc:creator>upstream</dc:creator>
      <guid isPermaLink="false">23995@/two/discussions</guid>
      <description><![CDATA[<p>I've only found the way to control all the alpha values of images through "tint".
But what I want is to change specific image's alpha value, even dynamically.
Dose anyone know the answer?
Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Help needed to manually mix ARGB pixels.</title>
      <link>https://forum.processing.org/two/discussion/23961/help-needed-to-manually-mix-argb-pixels</link>
      <pubDate>Tue, 29 Aug 2017 12:17:38 +0000</pubDate>
      <dc:creator>shawnlau</dc:creator>
      <guid isPermaLink="false">23961@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to manually mix ARGB pixels and the mix is coming out rather dull.</p>

<p>Is there a better way to manually mix ARGB?</p>

<p>EDIT: I found the correct way to do this. The corrected program is down a few posts ( if anyone is interested in the method).</p>

<pre><code>PImage A, B,C;
boolean showMix = false;
void setup(){

     size(600,600);
     A = createImage(600,600,ARGB);
     B = createImage(600,600,ARGB);
     C = createImage(600,600,ARGB);
     A.loadPixels();
     for(int i = 0; i &lt; 300; i++){
          for(int j = 0;j &lt; 300; j++){
               A.pixels[i * 600 + j]= 0x7FFF0000;
          }
     }
     A.updatePixels();
     B.loadPixels();
     for(int i = 150; i &lt; 450; i++){
          for(int j = 150;j &lt; 450; j++){
               B.pixels[i * 600 + j]= 0x7F00FF00;
          }
     } 
     B.updatePixels();  
     mix();  

}
void draw(){
     background(255);
     if(showMix)
          image(C,0,0);
     else{
          image(A,0,0);
          image(B,0,0);
     }
}
void keyPressed(){
     showMix = !showMix;
}
void mix(){
     float ba,br,bg,bb; //background a,r,g,b
     float fa,fr,fg,fb; //foreground
     float oa, or,og,ob; //output
     int a,r,g,b;
     A.loadPixels();
     B.loadPixels();
     C.loadPixels();
     for(int i = 0; i &lt; 600;i++){
          for(int j= 0;j&lt;600;j++){
               int index = i * 600 + j;
               ba=A.pixels[index]&gt;&gt;24 &amp; 0xFF; fa=B.pixels[index]&gt;&gt;24 &amp; 0xFF;
               br=A.pixels[index]&gt;&gt;16 &amp; 0xFF; fr=B.pixels[index]&gt;&gt;16 &amp; 0xFF;
               bg=A.pixels[index]&gt;&gt;8 &amp; 0xFF; fg=B.pixels[index]&gt;&gt;8 &amp; 0xFF;
               bb=A.pixels[index] &amp; 0xFF; fb=B.pixels[index] &amp; 0xFF;
               ba/=255;fa/=255;      //convert alpha to 0.0 - 1.0
               oa = fa + ba *(1.0-fa);
               or = (fr * fa) + ( br*ba*(1.0-fa) );
               og = (fg * fa) + ( bg*ba*(1.0-fa) );
               ob = (fb * fa) + ( bb*ba*(1.0-fa) );
               oa *= 255;  // convert to 0-255
               a=Math.round(oa); r=Math.round(or); g=Math.round(og); b=Math.round(ob);               
               C.pixels[index]= a&lt;&lt;24|r&lt;&lt;16|g&lt;&lt;8|b;
          }  
     }
     C.updatePixels();
}   
</code></pre>
]]></description>
   </item>
   <item>
      <title>Less CPU intensive way to scan pixels</title>
      <link>https://forum.processing.org/two/discussion/23592/less-cpu-intensive-way-to-scan-pixels</link>
      <pubDate>Wed, 26 Jul 2017 23:03:33 +0000</pubDate>
      <dc:creator>TimShaw</dc:creator>
      <guid isPermaLink="false">23592@/two/discussions</guid>
      <description><![CDATA[<p>Hi -</p>

<p>I am scanning an image line by line and outputting the greyscale of each pixel to Pure Data via OSC, all of it is working ok but it seems super intensive for the computer, the fans are on full speed and sometimes Processing crashes a few minutes in.</p>

<p>Is there anything I can do to make this code less intensive? Might be missing something obvious?</p>

<p>It could be because of the frameRate, and if so are there any suggestions of other ways of doing this? So that I can still run the scanning pretty fast</p>

<p>Thanks in advance for any help</p>

<pre><code>import oscP5.*;
import netP5.*;

NetAddress remote;
OscP5 oscP5;
//int incomingOSCData;
// int sendTestData;
// String msgType;

PImage img;
int x, y, s, r;

void setup() {
  size(500, 500);
  oscP5 = new OscP5(this,12000);
  remote = new NetAddress("127.0.0.1",3000);
  s = 10;
  stroke(255);
  reset();
  frameRate(200);
  img = loadImage("10.jpg");
  background(0);
  img.loadPixels();
}

void reset(){
  background(0);
  x = 0;
  y = 0;
  OscMessage msg = new OscMessage("/sync");
  msg.add(1);
  oscP5.send(msg,remote);
}

void draw() {
  if(x&gt;=width){ y+=s; x=0; }
  if(y&gt;=height) reset();
  delay(100);
  int loc = x + y*img.width;
  noStroke();
  color c = img.pixels[loc];
  // int alpha = (c &gt;&gt; 24) &amp; 0xFF;
  int red   = (c &gt;&gt; 16) &amp; 0xFF;
  int green = (c &gt;&gt; 8)  &amp; 0xFF;
  int blue  =  c        &amp; 0xFF;
  int gray = ((red + green + blue) / 3);
  // println(alpha + " " + red + " " + green + " " + blue);
  fill(c);
  rect(x++,y,4,4);
  // println(gray);
  OscMessage msg = new OscMessage("/grayscale");
  msg.add(gray);
  oscP5.send(msg,remote);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Any way to optimize this pixel overlay?</title>
      <link>https://forum.processing.org/two/discussion/23603/any-way-to-optimize-this-pixel-overlay</link>
      <pubDate>Thu, 27 Jul 2017 20:11:21 +0000</pubDate>
      <dc:creator>Abotics99</dc:creator>
      <guid isPermaLink="false">23603@/two/discussions</guid>
      <description><![CDATA[<p>Hi there, I'm currently working on a "retro" looking game and I've made a function that draws a pixelized overlay across the canvas. I'm currently working on optimizing it and would love any help.  It already runs fairly well (60fps) but compared to when it's not running (500+fps) I think it could do better.</p>

<pre><code>void setup() {
  size(1024,896,P2D);
  frameRate(500);
  noStroke();
  smooth(0);
}

void draw() {
  background(0);
  ellipse(mouseX,mouseY,100,100);
  if(mousePressed){
    drawPixels(256,224);
  }
  println(frameRate);
}

void drawPixels(int retroResX, int retroResY) {
  int pixelScale = width/retroResX;
  loadPixels();
  for(int y=0;y&lt;retroResY;y++){
    for(int x=0;x&lt;retroResX;x++){
      for(int py=0;py&lt;pixelScale;py++){
        for(int px=0;px&lt;pixelScale;px++) {
          pixels[((py+(y*pixelScale))*width)+(px+(x*pixelScale))] = pixels[(y*width*pixelScale)+(x*pixelScale)];
        }
      }
    }
  }
  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>pixels array edge detection</title>
      <link>https://forum.processing.org/two/discussion/23593/pixels-array-edge-detection</link>
      <pubDate>Thu, 27 Jul 2017 01:18:52 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">23593@/two/discussions</guid>
      <description><![CDATA[<p>Does anyone know how to turn this processing code</p>

<p><a href="https://www.openprocessing.org/sketch/441474" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/441474</a></p>

<p>into p5.js?</p>

<p><a href="https://www.openprocessing.org/sketch/441671" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/441671</a></p>
]]></description>
   </item>
   <item>
      <title>How to modify PImage.pixels in processing.js</title>
      <link>https://forum.processing.org/two/discussion/23558/how-to-modify-pimage-pixels-in-processing-js</link>
      <pubDate>Sat, 22 Jul 2017 23:55:53 +0000</pubDate>
      <dc:creator>Ignotus</dc:creator>
      <guid isPermaLink="false">23558@/two/discussions</guid>
      <description><![CDATA[<p>I have some code that runs just fine in Processing 3. I am testing it out in processing.js, with the usual HTML wrapper.</p>

<pre><code>// <a href="/two/profile/pjs">@pjs</a> preload must be used to preload the image   
/* <a href="/two/profile/pjs">@pjs</a> preload="graynoiz_128.png"; */

// Works in Processing. Does not work in Processing.js. Why  not?

PImage b;
String imageName = "graynoiz_128.png";
int shift;

public void setup() {
  size(128, 128);
  this.frameRate = 24;
  shift = 4;
  b = loadImage(imageName);
}

public void draw() {
  background(233, 233, 199);
  image(b, 0, 0);
  if (this.frameCount &gt; 2) {
    b.loadPixels();
    color[] pix = b.pixels;
    rotateLeft(b.pixels, shift);
    b.updatePixels();
  }
}

/**
 * Rotates an array of ints left by d values. Uses efficient "Three Rotation" algorithm.
 * <a href="/two/profile/param">@param</a> arr   array of ints to rotate
 * <a href="/two/profile/param">@param</a> d     number of elements to shift
 */
public void rotateLeft(color[] arr, int d) {
  d = d % arr.length;
  reverseArray(arr, 0, d - 1);
  reverseArray(arr, d, arr.length - 1);
  reverseArray(arr, 0, arr.length - 1);
}

/**
 * Reverses an arbitrary subset of an array.
 * <a href="/two/profile/param">@param</a> arr   array to modify
 * <a href="/two/profile/param">@param</a> l     left bound of subset to reverse
 * <a href="/two/profile/param">@param</a> r     right bound of subset to reverse
 */
public void reverseArray(color[] arr, int l, int r) {
  color temp;
  while (l &lt; r) {
    temp = arr[l];
    arr[l] = arr[r];
    arr[r] = temp;
    l++;
    r--;
  }
}
</code></pre>

<p>The image loads just fine in FireFox (using MAMP). It shifts/animates fine in Processing, but not in the web page.</p>

<p>I want to do more complex things with the image pixels, but there seems to be some kind of error I need to resolve first, though nothing shows in the console.</p>

<p>Thanks,</p>

<p>-- Paul</p>
]]></description>
   </item>
   <item>
      <title>How do I add an interactive menu to a code which uploads a picture and uses it in the code?</title>
      <link>https://forum.processing.org/two/discussion/23413/how-do-i-add-an-interactive-menu-to-a-code-which-uploads-a-picture-and-uses-it-in-the-code</link>
      <pubDate>Wed, 12 Jul 2017 12:48:11 +0000</pubDate>
      <dc:creator>aless100</dc:creator>
      <guid isPermaLink="false">23413@/two/discussions</guid>
      <description><![CDATA[<p>The code draws the image with paint splatters. 
Link: <a href="https://www.openprocessing.org/sketch/392202" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/392202</a>
All credits to Jason Labbe.</p>
]]></description>
   </item>
   <item>
      <title>trying to convert a code from Processing to p5.js with pixels[]</title>
      <link>https://forum.processing.org/two/discussion/23404/trying-to-convert-a-code-from-processing-to-p5-js-with-pixels</link>
      <pubDate>Tue, 11 Jul 2017 12:34:43 +0000</pubDate>
      <dc:creator>omerpekin</dc:creator>
      <guid isPermaLink="false">23404@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I am trying to use p5.js and insisting on learning javascript - which is harder than I thought!!</p>

<p>Below is the Processing script I wrote that basically smears an image.</p>

<p>It is a fairly simple script; 
It finds a random pixel
It gets the color of that pixel
matches the following 10-100 pixels color to the original random pixel.</p>

<p>So somehow this explanation on get() reference about doing the same operation with pixels[] confused me a bit. 
<a href="https://p5js.org/reference/#/p5/get" target="_blank" rel="nofollow">https://p5js.org/reference/#/p5/get</a></p>

<p>Now, when I wrote this script and tried it, what I see is basically the original earth image and nothing happens.</p>

<p>the most confusing part is <code>var</code> instead of <code>color</code> I don't understand how I should specify so that my program gets the color information of that pixel instead of whatever pixels[] array is providing as an information.</p>

<p>Here is the original Processing Script:</p>

<pre><code>import processing.pdf.*;
import java.util.Calendar;

import processing.pdf.*;
import java.util.Calendar;

PImage img;
PGraphics pg; 
boolean drawn = false;
String naming;

void setup() {
  img = loadImage("http://" + "cdni.pageflow.codevise.de/main/video_files/posters/000/000/370/v3/medium/poster-0.JPG");
  size(img.width, img.height);
  pg = createGraphics(width, height);
  pg.beginDraw();
  pg.image( img, 0, 0, width, height);
  pg.endDraw();
}

void draw() {
  pg.loadPixels();
  if(!drawn){
    int numberOfRands = 100;
  for(int i = 0; i &lt; numberOfRands; i++){
    int r= int(random(height*width));
    color c = pg.pixels[r];
    for(int j = 0; j &lt; random(10,100); j++){
      if(r+j &lt; pg.pixels.length){
        pg.pixels[r+j] = c;
      }
    } 
  }
//  drawn = true;
  }
  pg.updatePixels();
  image(pg, 0, 0, width, height);
}
</code></pre>

<p>and here is the converted script:
you can also see the same p5.js script here: <a href="https://www.openprocessing.org/sketch/438964" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/438964</a></p>

<pre><code>var img, pg;
var canvasOfset = 10;
var fillColor;
var drawn = false;

function preload() {
  img = loadImage('http://" + "cdni.pageflow.codevise.de/main/video_files/posters/000/000/370/v3/medium/poster-0.JPG');
}



function setup() {
  createCanvas(windowWidth - canvasOfset, windowHeight - canvasOfset);
  pg = createGraphics(width, height);
  pg.image(img, 0, 0, width, height);
}


function draw() {
  pg.loadPixels();
  var numberOfRands = 100;
  var d = pixelDensity();
  for (var j = 0; j &lt; numberOfRands; j += 4) {
    var off = random(width * height);
    var fillColor = color(pg.pixels[off], pg.pixels[off + 1], pg.pixels[off + 2], pg.pixels[off + 3]);
    for (var i = 0; i &lt; random(120, 1600); i += 4) {
      pg.pixels[off + i] = color(fillColor);
      pg.pixels[off + i + 1] = green(fillColor);
      pg.pixels[off + i + 2] = blue(fillColor);
      pg.pixels[off + i + 3] = alpha(fillColor);
    }
  }

  pg.updatePixels();
  image(pg, 0, 0, width, height);
}



function windowResized() {
  resizeCanvas(windowWidth - canvasOfset, windowHeight - canvasOfset);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>pixel array with an image</title>
      <link>https://forum.processing.org/two/discussion/23382/pixel-array-with-an-image</link>
      <pubDate>Mon, 10 Jul 2017 00:31:18 +0000</pubDate>
      <dc:creator>tim50</dc:creator>
      <guid isPermaLink="false">23382@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>Does anybody know why my code isn't working?</p>

<p>Thanks,</p>

<p><a href="https://www.openprocessing.org/sketch/438530" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/438530</a></p>
]]></description>
   </item>
   <item>
      <title>Management of size() on Retina displays</title>
      <link>https://forum.processing.org/two/discussion/23321/management-of-size-on-retina-displays</link>
      <pubDate>Wed, 05 Jul 2017 12:38:03 +0000</pubDate>
      <dc:creator>paulbourke</dc:creator>
      <guid isPermaLink="false">23321@/two/discussions</guid>
      <description><![CDATA[<p>First, let me say I'm new to Processing, but an accomplished programmer and was recently looking for something for quick algorithm prototyping, and have found Processing a perfect match for what I was looking for.</p>

<p>My question relates to size(), pixelDensity() and displayDensity() ... I believe I understand them correctly, the only thing that tripped me up was the need to use pixelWidth and pixelHeight when doing pixel based operations. But it would seem to me that if I'm creating something for a "normal" display, to be projected say, then I might use something like size(1920,1080). But on a retina display like my MacBookPro I would normally use something smaller, but knowing that the quality will be the same as higher in that smaller window.</p>

<p>In short it doesn't seem that I can make decisions on the values for size() based upon displayDensity()? It would seem like a natural thing to want to do if developing for both retina and non-retina. Or more fundamental, I would like to be able to base the values for size() on the display pixel dimensions. Any way to do this?</p>
]]></description>
   </item>
   <item>
      <title>Transparency</title>
      <link>https://forum.processing.org/two/discussion/23017/transparency</link>
      <pubDate>Sat, 10 Jun 2017 22:42:28 +0000</pubDate>
      <dc:creator>Student1234</dc:creator>
      <guid isPermaLink="false">23017@/two/discussions</guid>
      <description><![CDATA[<p>Accidentally made this a discussion earlier, but is it possible to make an image transparent? My plan is to have the image become transparent after being clicked on.</p>
]]></description>
   </item>
   <item>
      <title>Faster way of drawing a byte to the screen ?</title>
      <link>https://forum.processing.org/two/discussion/22978/faster-way-of-drawing-a-byte-to-the-screen</link>
      <pubDate>Wed, 07 Jun 2017 18:52:24 +0000</pubDate>
      <dc:creator>aephx</dc:creator>
      <guid isPermaLink="false">22978@/two/discussions</guid>
      <description><![CDATA[<p>Hey guys!
I've made a Program that basically emulates a 256x192 (monochrome)screen in processing.
The byte-array, in which i store the pixel-data, has 6kb.  (8pixel per byte, to a total of 6144bytes). 
1 drawing cycle of the screen (if every pixel is a 1==white) takes the Program around 6 seconds.</p>

<p>So my question is, is there a faster way of drawing a byte to the screen than my approach?</p>

<p>Code of the drawing "algorithm":</p>

<p><code>for (int I=0; I&lt;6144; I++){
    int x,y = I/32;
    for(int X=0; X&lt;32; X++) {
      x = X*8;
      // checks if the bit is == 1 and then draws the point
      if ( (DataIn[I] &amp; 0x01) &gt; 0) point(x,y);
      if ( (DataIn[I] &amp; 0x02) &gt; 0) point(x+1,y);
      if ( (DataIn[I] &amp; 0x04) &gt; 0) point(x+2,y);
      if ( (DataIn[I] &amp; 0x08) &gt; 0) point(x+3,y);
      if ( (DataIn[I] &amp; 0x10) &gt; 0) point(x+4,y);
      if ( (DataIn[I] &amp; 0x20) &gt; 0) point(x+5,y);
      if ( (DataIn[I] &amp; 0x40) &gt; 0) point(x+6,y);
      if ( (DataIn[I] &amp; 0x80) &gt; 0) point(x+7,y);
    }
  }</code></p>

<p>also sorry about my bad english</p>
]]></description>
   </item>
   <item>
      <title>How to translate byte[] to PImage?</title>
      <link>https://forum.processing.org/two/discussion/14814/how-to-translate-byte-to-pimage</link>
      <pubDate>Mon, 08 Feb 2016 10:34:01 +0000</pubDate>
      <dc:creator>czerny</dc:creator>
      <guid isPermaLink="false">14814@/two/discussions</guid>
      <description><![CDATA[<p>in Server sketch, i take a picture with Processing’s Video library and send a byte array to client’s buffer</p>

<p>like this,,</p>

<pre><code>/**
void mousePressed() {
 capture.save(“temp.jpg");
 byte[] b=loadBytes(“temp.jpg");
 server.write(b);
} 
*/
</code></pre>

<p>but i have no idea how to convert this byte array to PImage format in Client’s sketch.</p>

<p>is there any byte[] to Pimage converting method in processing???</p>
]]></description>
   </item>
   <item>
      <title>How to properly shuffle a pixelArray</title>
      <link>https://forum.processing.org/two/discussion/22820/how-to-properly-shuffle-a-pixelarray</link>
      <pubDate>Mon, 29 May 2017 23:10:56 +0000</pubDate>
      <dc:creator>hanray</dc:creator>
      <guid isPermaLink="false">22820@/two/discussions</guid>
      <description><![CDATA[<p>Finally decided to join this forum since I rely so much on other's people's questions/answers.</p>

<p>My question today is how to randomly place a pixel after loading it. I'm not interested in manipulating it's colors just the pixels. Here is my function:</p>

<pre><code>void glitch () {
  if (!glitchComplete) {

    // load the image's pixels into .pixel array 
    img.loadPixels();
    //iterate through each pixel row and column and apply the desired changes
    for (int x = 0; x &lt; img.width; x++) {

      for (int y = 0; y &lt; img.height; y++) {

        color pixelColor = img.pixels[y + x * img.height];
        //the formula I learned from the processing docs

        int loc = y + x * img.height;

        int randomOffset = int(random(5,20));

        //slight shift in their original location
        loc = loc + randomOffset;

        img.pixels[loc] = pixelColor;
      }
    }//end of double loop

    img.updatePixels();
    glitchComplete = true;

    // load updated image onto surface
    image(img, 0, 0, img.width, img.height);
  }
</code></pre>

<p>For anyone new to processing, just a heads up: " loc = loc + randomOffset;" will NOT work because this position technically doesnt exist in the pixel array. If you want to place a pixel in a random location, it must be a random location within the bounds of the pixel array (hope im using the right terminology here) .</p>

<p>My thinking here was I wanted to redraw the pixel at it's original location &amp; color and simply shift it over a few pixels to produce something close to a glitch effect(instead of re-colouring the image). So can anyone suggest another method that can achieve the same results.</p>

<p>Your time and input is very much appreciated.</p>
]]></description>
   </item>
   <item>
      <title>Problem combine 2 codes...</title>
      <link>https://forum.processing.org/two/discussion/22772/problem-combine-2-codes</link>
      <pubDate>Fri, 26 May 2017 12:03:16 +0000</pubDate>
      <dc:creator>Nicolejansen</dc:creator>
      <guid isPermaLink="false">22772@/two/discussions</guid>
      <description><![CDATA[<p>I got those two, and want to combine them but really, everything is false... Can someone help me out? 
<strong>first</strong></p>

<pre><code>// Click the mouse to memorize a current background image
import processing.video.*;
import gab.opencv.*;

// Variable for capture device
Capture video;
OpenCV opencv;

// Saved background
PImage backgroundImage;

// How different must a pixel be to be a foreground pixel
float threshold = 20;

void setup() {
  String[] cameras = Capture.list();
  //printArray(cameras);
  size(1280, 720);
  //video.width = 1280;
  //video.height = 720;
  video = new Capture(this, 1280, 720, cameras[76]);

  video.start();

  opencv = new OpenCV(this, 1280, 720);
  opencv.startBackgroundSubtraction(5, 3, 0.5);

  // Create an empty image the same size as the video
  backgroundImage = createImage(video.width, video.height, RGB);




}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  if (video.available() == true) {
    video.read();
  }
  image(video, random(width),random(height));

  opencv.loadImage(video);

  opencv.updateBackground();

  opencv.dilate();
  opencv.erode();

  noFill();
  stroke(255, 0, 0);
  strokeWeight(3);
  for (Contour contour : opencv.findContours()) {
    contour.draw();

}
}

void mousePressed() {

}
</code></pre>

<p>**
    **second code to combine with first one****
    **</p>

<pre><code>import processing.video.*;

Capture video;
int signal = 0;

//the buffer for storing video frames
ArrayList frames;

//different program modes for recording and playback
int mode = 0;
int MODE_NEWBUFFER = 0;
int MODE_RECORDING = 1;
int MODE_PLAYBACK = 2;

int currentX = 0;

void setup() {
  size(640, 480);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Capture(this, width, height);

  // Start capturing the images from the camera
  video.start();  
}

void captureEvent(Capture c) {
  c.read();

  //create a new buffer in case one is needed
  if (mode == MODE_NEWBUFFER) {
    frames = new ArrayList();
    mode = MODE_RECORDING;
  }

  //record into the buffer until there are enough frames
  if (mode == MODE_RECORDING) {
    //copy the current video frame into an image, so it can be stored in the buffer
    PImage img = createImage(width, height, RGB);
    video.loadPixels();
    arrayCopy(video.pixels, img.pixels);

    frames.add(img);

    //in case enough frames have been recorded, switch to playback mode
    if (frames.size() &gt;= width) {
      mode = MODE_PLAYBACK;
    }
  }
}

void draw() { 
  loadPixels();

  //code for the recording mode 
  if (mode == MODE_RECORDING) {
    //set the image counter to 0
    int currentImage = 0;

    //begin a loop for displaying pixel columns
    for (int x = 0; x &lt; video.width; x++) {
      //go through the frame buffer and pick an image using the image counter
      if (currentImage &lt; frames.size()) {
        PImage img = (PImage)frames.get(currentImage);

        //display a pixel column of the current image
        if (img != null) {
          img.loadPixels();

          for (int y = 0; y &lt; video.height; y++) {
            pixels[x + y * width] = img.pixels[x + y * video.width];
          }  
        }

        currentImage++;

      } 
      else {
        break;
      }
    }
  }

  if (mode == MODE_PLAYBACK) {  

    for (int x = 0; x &lt; video.width; x++) {
      PImage img = (PImage)frames.get(x);

      if (img != null) {
        img.loadPixels();
        for(int y = 0; y &lt; video.height; y++) {
          pixels[x + y * width] = img.pixels[currentX + y * video.width];
        }  
      }
    } 

    currentX++;

    if(currentX &gt;= video.width) {
      mode = MODE_NEWBUFFER;
      //reset the column counter
      currentX = 0;
    }
  }

  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Why is the video in canvas not working p5js?</title>
      <link>https://forum.processing.org/two/discussion/22662/why-is-the-video-in-canvas-not-working-p5js</link>
      <pubDate>Thu, 18 May 2017 19:05:59 +0000</pubDate>
      <dc:creator>banana</dc:creator>
      <guid isPermaLink="false">22662@/two/discussions</guid>
      <description><![CDATA[<p>I was watching this video: 
10.4 Brightness Mirror - p5.js Tutorial</p>

<p>and I am not getting my code to work:</p>

<pre>

var video;

function setup() {
  createCanvas(320, 240);
  pixelDensity(1);
  video = createCapture(VIDEO).size(320, 240);
}

function draw() {
  background(51);

  video.loadPixels();

  //pixels from canvas
  loadPixels();
  for (var y = 0; y &lt; height; y++) {
    for (var x = 0; x &lt; width; x++) {
      var index = (x + y * width)*4;
      pixels[index+0] = video.pixels[index+0];
      pixels[index+1] = video.pixels[index+1];
      pixels[index+2] = video.pixels[index+2];
      pixels[index+3] = 255;      
    }
  }
  updatePixels();
}

</pre>

<p>It shows like a ghost-like video :/ 
<a href="http://xxnotmuchxx.tumblr.com/post/160811589716" target="_blank" rel="nofollow">http://xxnotmuchxx.tumblr.com/post/160811589716</a></p>
]]></description>
   </item>
   <item>
      <title>What could be causing 'array.array assignment index out of range' error?</title>
      <link>https://forum.processing.org/two/discussion/22563/what-could-be-causing-array-array-assignment-index-out-of-range-error</link>
      <pubDate>Sat, 13 May 2017 15:41:48 +0000</pubDate>
      <dc:creator>dallas_borealis</dc:creator>
      <guid isPermaLink="false">22563@/two/discussions</guid>
      <description><![CDATA[<p>I'm attempting to do Dan Shiffman's Pixel Array in Python but get the error after just a few iterations. Here's the code:</p>

<pre><code>inc = 0.01
def setup():
    size(6, 5)

def draw():
    # background(50)
    global inc
    yoff = 0
    loadPixels()
    for y in range(height-1):
        xoff = 0
        for x in range(width):
            idx = (x + y * width) * 4
            r = noise(xoff, yoff) * 255
            pixels[idx+0] = r
            pixels[idx+1] = r
            pixels[idx+2] = r
            pixels[idx+3] = 255
            xoff += inc
        yoff += inc
    updatePixels()
</code></pre>

<p>The error appears here: <code>pixels[idx+2] = r</code></p>

<p>Thanks for any help!</p>

<p>~dallas_borealis</p>
]]></description>
   </item>
   <item>
      <title>Create new image with pixels</title>
      <link>https://forum.processing.org/two/discussion/22506/create-new-image-with-pixels</link>
      <pubDate>Wed, 10 May 2017 21:59:21 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">22506@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>I'm trying to build a new image, capturing only part that interests me from another, I used this base to begin with:
<a href="https://processing.org/tutorials/pixels/" target="_blank" rel="nofollow">https://processing.org/tutorials/pixels/</a></p>

<p>I am in doubt as to the image below, the part where it seems "rainbow", would I use the function (hue), or (r, g, b) individually to capture?</p>

<p>And what about the circled part (very badly done, sorry) more in the middle, would have to use the function (brightness), since it is kind of "brightness" in the image?</p>

<p>Thanks any hint, below is the sample code, and the image as template.</p>

<p>Thank you,</p>

<pre><code>    PImage source;       
    PImage destination;  
    float threshold = 0;

    void setup() {
      size(400, 300);
      source = loadImage("Img01.jpg"); 
      source.resize(400, 300); 
      destination = createImage(source.width, source.height, RGB);
    }

    void draw() {  
      //threshold = 127;
      threshold = 70;

      source.loadPixels();
      destination.loadPixels();

      for (int x = 0; x &lt; source.width; x++) {
        for (int y = 0; y &lt; source.height; y++ ) {
          int loc = x + y*source.width;
          if (brightness(source.pixels[loc]) &gt; threshold) {
          //if (hue(source.pixels[loc]) &gt; threshold) {
            //destination.pixels[loc]  = source.pixels[loc];  // White
            destination.pixels[loc]  = source.pixels[loc];
          }
        }
      }

      destination.updatePixels();
      image(destination,0,0);
      //image(source,0,0);
    }

    void keyPressed(){
      if (key == 'A' || key == 'a')
        threshold = threshold + 10;

      if (key == 'D' || key == 'd')
        threshold = threshold - 10;

      println(threshold);  
    }
</code></pre>

<p><img src="https://forum.processing.org/two/uploads/imageupload/514/V1CE41MQRF0U.png" alt="Imagem01" title="Imagem01" /></p>
]]></description>
   </item>
   <item>
      <title>how to draw over a video in P3</title>
      <link>https://forum.processing.org/two/discussion/22183/how-to-draw-over-a-video-in-p3</link>
      <pubDate>Tue, 25 Apr 2017 02:16:00 +0000</pubDate>
      <dc:creator>c_borgs</dc:creator>
      <guid isPermaLink="false">22183@/two/discussions</guid>
      <description><![CDATA[<p>I have been trying to emulate something like this sketch: <span class="VideoWrap"><span class="Video YouTube" id="youtube-z-3ZGrBjQ4g"><span class="VideoPreview"><a href="http://youtube.com/watch?v=z-3ZGrBjQ4g"><img src="http://img.youtube.com/vi/z-3ZGrBjQ4g/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span>
with a few other features as well. 
i've been able to track the color but have not been successful at keeping the trial it creates as a drawing over the video.
I've tried topLayer in P2 without success, and i am now thinking about how i might make the color track a separate object. Below is what I have so far</p>

<p>Any and all insight/ help would be greatly appreciated!!</p>

<p>`
    import processing.video.*;</p>

<pre><code>// Variable for capture device
Capture video;

// A variable for the color we are searching for.
color trackColor; 

float threshold = 25;

void setup() {
  size(640, 360);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[3]);
  video.start();
  // Start off tracking for red
  trackColor = color(255, 0, 0);
}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  video.loadPixels();
  image(video, 0, 0);

  textSize(12);
  text("pick a tool, click the color, draw yourself a friend", 10, 30); 
  stroke(#FFFFFF);

  textSize(12);
  text("press space to save your sketch", 10, 330); 
  fill(#FFFFFF);  

  // XY coordinate of closest color
  float avgX = 0;
  float avgY = 0;

  int count = 0;

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; video.height; y++ ) {
      int loc = x + y * video.width;
      // What is current color
      color currentColor = video.pixels[loc];
      float r1 = red(currentColor);
      float g1 = green(currentColor);
      float b1 = blue(currentColor);
      float r2 = red(trackColor);
      float g2 = green(trackColor);
      float b2 = blue(trackColor);

      // Using euclidean distance to compare colors
      float d = dist(r1, g1, b1, r2, g2, b2); // We are using the dist( ) function to compare the current color with the color we are tracking.

      if (d &lt; threshold) {
        avgX += x;
        avgY += y;
        count++;
      }
    }
  }

  // We only consider the color found if its color distance is less than 10. 
  // This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
  if (count &gt; 0) { 
    avgX = avgX / count;
    avgY = avgY / count;

    // Draw a circle at the tracked pixel
    fill(trackColor);
    noStroke();
    ellipse(avgX, avgY, 8, 8);
  }
}

void mousePressed() {
  // Save color where the mouse is clicked in trackColor variable
  int loc = mouseX + mouseY*video.width;
  trackColor = video.pixels[loc];
}

void keyPressed() {
  if (key == ' ') { //space bar
  saveFrame("picture-####.jpg");
  }
}
</code></pre>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>interactive screen using live video, changing letters positions</title>
      <link>https://forum.processing.org/two/discussion/22123/interactive-screen-using-live-video-changing-letters-positions</link>
      <pubDate>Fri, 21 Apr 2017 11:34:54 +0000</pubDate>
      <dc:creator>MilaYume</dc:creator>
      <guid isPermaLink="false">22123@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm new to programming with Processing. Trying to make a code for my art bachelor degree. What I want to do: make the interactive screen, filled with letters(text), with a live cam recording what's happening in front, detecting motion. When there is a motion letter that meets motion line(human body contours) flips position with a letter from the side with motion come from. 
for that as a base, I used raindrops sketch and Shiffman's Example 16-13: Simple motion detection.
But now I'm getting a gray screen and letters appear non-stop. Did I mess up something with arrays? should text be put not in a string? I read about Kinect but not sure if it would help at this point. Hope to get hints or something that to do next :]</p>

<pre><code>    import processing.video.*;
    import java.awt.Frame;
    import java.awt.Image;
    import java.text.*;

    Capture cam;
    Letter[][] drops;
    int dropsLength;
    PImage prevFrame;
    int sWidth = 1280;
    int sHeight = 720;

    String inputString = "Įsivaizduokime pasaulį, kur visi viską žino tiksliai, ir niekada neklysta. Niekam nekiltų abejoių, koks bus rytoj oras, kaip išsaugoti tirpstačius ledynus, ar koks visatos dydis. Žvelgiant į krentantį kamuoliuką kiekvienas galėtų pasakyti: -  O šito kamuoliuko kritimo greitis 6,325 m/s. -  Tikrai taip - atsakytų kitas. Ir viskas, daugiau nebebūtų jokių diskusijų, ieškojimų, matavimų. Su absoliučiu žinojimu gyvenimas taptų nebeįdomus, monotoniškas, tokiu atveju net progresas neįmanomas. Kai pradedu taip galvoti, džiaugiuosi nežinojimu, diskusijų galimybe, tiesos ieškojimu. Klaida suvokiama kaip neišvengiamas procesas teisybės ieškojime leidžia drąsiai žengti į praktikos sritį, nebijoti suklysti, o neteisingus procesus paversti progresu, žingsneliu link tikslo. Menininkas nebėra tas genijus, kuris turi sukurti kažką naujo, tarsi nežemiško, keičiančio visą mūsų suvokimą. Jo praktikos esmė eksperimentuoti ir klysti, organizuoti jau esamomis reikšmėmis ir kurti nau";
    char[] inputLetters;
    int dupStrings = 3;   //times to dublicate text
    int k = 800;
    float threshold = 50;

    void settings() {
      size(1280, 720);
    }
    void setup() {
      String[] cameras = Capture.list();

      drops = new Letter[dupStrings][inputString.length()];  //[inputString.length()]; 

      int wspace = 50;
      inputLetters = new char[inputString.length()]; 
      splitString();


      // first row hight
      int addLineHeight = 30;                                                       
      for (int i = 0; i &lt; dupStrings; i++) {     
            for (int j = 0; j &lt; inputLetters.length; j++) {   
                 if  (inputLetters[j] &lt; k + wspace ){
                   Letter testLetter = new Letter(inputLetters[j]);
                   testLetter.x = wspace;
                   testLetter.y = addLineHeight;
                   drops[i][j] = testLetter;
                   wspace += 10;   //spaces between letters

                   // new row
                   if (wspace &gt;= sWidth) {   
                                wspace = 10;
                               addLineHeight += 40; } // space between 

                    }
                           else {
                               addLineHeight += 50;
                                }
                                                                  }
                                               }
    // cam conect//

      if (cameras.length == 0) {
        println("There are no cameras available...");
        size(400, 400);
        exit();
      }
      else {
        cam = new Capture(this, sWidth, sHeight);
        cam.start();
        cam.loadPixels();
        prevFrame = createImage(cam.width, cam.height, RGB);

        size(sWidth, sHeight);
      }
      dropsLength = inputString.length();
    }

    void captureEvent(Capture cam) {
      // Save previous frame for motion detection!!
      prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height); 
      // Before we read the new frame, we always save the previous frame for comparison!```
      prevFrame.updatePixels();  // Read image from the camera
      cam.read();
    }


    void splitString() { 

      for (int i = 0; i &lt; inputString.length() ; i++) {
        inputLetters[i] = inputString.charAt(i);
      }
    }

    void draw() {

        loadPixels();
      cam.loadPixels();
      prevFrame.loadPixels();
        // Begin loop to walk through every pixel
      for (int x = 0; x &lt; cam.width; x ++ ) {
        for (int y = 0; y &lt; cam.height; y ++ ) {

          int loc = x + y*cam.width;            // Step 1, what is the 1D pixel location
          color current = cam.pixels[loc];      // Step 2, what is the current color
          color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current); 
          float g1 = green(current); 
          float b1 = blue(current);
          float r2 = red(previous); 
          float g2 = green(previous); 
          float b2 = blue(previous);
          float diff = dist(r1, g1, b1, r2, g2, b2);

          // Step 5, How different are the colors?
          // If the color at that pixel has changed, then there is motion at that pixel.
          if (diff &gt; threshold) { 
            // If motion, display black
            pixels[loc] = color(0);
          } else {
            // If not, display white
            pixels[loc] = color(255);
          }
        }
      }

       //Responding to the brightness/color of the screen
       for (int i = 0; i &lt; dupStrings; i++) {
        for (int j = 0; j &lt; dropsLength; j++) {

          if (drops[i][j].y &lt; sHeight &amp;&amp; drops[i][j].y &gt; 0) {   
           int loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;                                           
           float bright = brightness(cam.pixels[loc]);                                                                                                                                                          
            if (bright &gt; threshold) {   
              drops[i][j].dropLetter();
              drops[i][j].upSpeed = 1;
            }
            else {                                                                            
              if (drops[i][j].y &gt; threshold) {
                int aboveLoc = loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;
                float aboveBright = brightness(cam.pixels[aboveLoc]);
                if (aboveBright &lt; threshold) {                                              
                  drops[i][j].liftLetter();
                  drops[i][j].upSpeed = drops[i][j].upSpeed * 5;                           
                }
              }
            }
          }
          else {
            drops[i][j].dropLetter(); 
          }

          drops[i][j].drawLetter();
          cam.updatePixels();
        }
      }
    }

    class Letter {
      int x;
      int y; 
      int m;
      char textLetter;
      int upSpeed;
      int alpha = 150;
      Letter(char inputText) {
        x = 100;
        y = 100;
        textLetter = inputText;
        textSize(16);
        upSpeed = 1;
      }
      void drawLetter() {
       // if ( m &lt; 1) {
        fill(150, 150, 150 , alpha);                 
        text(textLetter, x, y);

      }

      void letterFade() {
        alpha -= 5;
        if(alpha &lt;= 0) {
          y = int(random(-350, 0));
          alpha = 255; 
        }
      }


      void dropLetter() {
      //  y++;                         
        if (y &gt; 730) {
          letterFade();
        }
      }

      void liftLetter() {
        int newY = y - upSpeed;       
        if (newY &gt;= 0) {
          y = newY;
        }
        else {
          y = 0;
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Get Depth Value for Each Pixel</title>
      <link>https://forum.processing.org/two/discussion/21990/get-depth-value-for-each-pixel</link>
      <pubDate>Fri, 14 Apr 2017 10:08:18 +0000</pubDate>
      <dc:creator>CharlesDesign</dc:creator>
      <guid isPermaLink="false">21990@/two/discussions</guid>
      <description><![CDATA[<p>Hi All,</p>

<p>I'd really appreciate some help on this, I'm using the KinectPV2 library which is great but very poorly documented.</p>

<p>With reference to the example "MapDepthToColor" copied below I'm trying to retrieve the depth for each RGB pixel. I'm having a hard time decrypting what's going on, can someone help me out?</p>

<p>Thanks in advance,
Charles</p>

<pre><code>/*
Thomas Sanchez Lengeling.
<a href="http://codigogenerativo.com/" target="_blank" rel="nofollow">http://codigogenerativo.com/</a>

KinectPV2, Kinect for Windows v2 library for processing

Color to fepth Example,
Color Frame is aligned to the depth frame
*/

import KinectPV2.*;

KinectPV2 kinect;

int [] depthZero;

//BUFFER ARRAY TO CLEAN DE PIXLES
PImage depthToColorImg;

void setup() {
  size(1024, 848, P3D);

  depthToColorImg = createImage(512, 424, PImage.RGB);
  depthZero    = new int[ KinectPV2.WIDTHDepth * KinectPV2.HEIGHTDepth];

  //SET THE ARRAY TO 0s
  for (int i = 0; i &lt; KinectPV2.WIDTHDepth; i++) {
    for (int j = 0; j &lt; KinectPV2.HEIGHTDepth; j++) {
      depthZero[424*i + j] = 0;
    }
  }

  kinect = new KinectPV2(this);
  kinect.enableDepthImg(true);
  kinect.enableColorImg(true);
  kinect.enablePointCloud(true);

  kinect.init();
}

void draw() {
  background(0);

  float [] mapDCT = kinect.getMapDepthToColor(); // Length: 434,176

  //get the raw data from depth and color
  int [] colorRaw = kinect.getRawColor(); // Length: 2,073,600

  //clean de pixels
  PApplet.arrayCopy(depthZero, depthToColorImg.pixels);

  int count = 0;
  depthToColorImg.loadPixels();
  for (int i = 0; i &lt; KinectPV2.WIDTHDepth; i++) {
    for (int j = 0; j &lt; KinectPV2.HEIGHTDepth; j++) {

      //incoming pixels 512 x 424 with position in 1920 x 1080
      float valX = mapDCT[count * 2 + 0];
      float valY = mapDCT[count * 2 + 1];

      //maps the pixels to 512 x 424, not necessary but looks better
      int valXDepth = (int)((valX/1920.0) * 512.0);
      int valYDepth = (int)((valY/1080.0) * 424.0);

      int  valXColor = (int)(valX);
      int  valYColor = (int)(valY);

      if ( valXDepth &gt;= 0 &amp;&amp; valXDepth &lt; 512 &amp;&amp; valYDepth &gt;= 0 &amp;&amp; valYDepth &lt; 424 &amp;&amp;
        valXColor &gt;= 0 &amp;&amp; valXColor &lt; 1920 &amp;&amp; valYColor &gt;= 0 &amp;&amp; valYColor &lt; 1080) {
        color colorPixel = colorRaw[valYColor * 1920 + valXColor];
        //color colorPixel = depthRaw[valYDepth*512 + valXDepth];
        depthToColorImg.pixels[valYDepth * 512 + valXDepth] = colorPixel;
      } 
      count++;
    }
  }
  depthToColorImg.updatePixels();

  image(depthToColorImg, 0, 424);
  image(kinect.getColorImage(), 0, 0, 512, 424);
  image(kinect.getDepthImage(), 512, 0);

  text("fps: "+frameRate, 50, 50);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Using createGraphics().get() in the draw loop causing memory usage?</title>
      <link>https://forum.processing.org/two/discussion/22039/using-creategraphics-get-in-the-draw-loop-causing-memory-usage</link>
      <pubDate>Mon, 17 Apr 2017 03:03:56 +0000</pubDate>
      <dc:creator>Tsa6</dc:creator>
      <guid isPermaLink="false">22039@/two/discussions</guid>
      <description><![CDATA[<p>Hello, and thank you so much for your time.  I've been working on a project, and found it to be using a ton of memory -- enough that it crashed the program it was being built for.  I spent a couple days poking around to no avail.  I did, however, figure out some of the details of the problem, and was wondering if you kind folks would be able to help me pinpoint a solution.  Anyway, cutting to the chase:</p>

<p>The minimum amount of code I could recreate the problem with was this:</p>

<pre><code>var graphics;

function setup() {
    graphics = createGraphics(1000,1000);
}

function draw() {
    graphics.get();
}
</code></pre>

<p>This produces the expected result, but uses a ton of memory.  Here's the relevant info I could get out of Chrome dev tools:
<img src="http://i.imgur.com/dN3NA9M.png" alt="Task Manager" />
The memory is currently at 1.2 gigs, but I've seen it reach 3 gigs, given enought time.  Either way, that's way too much memory.</p>

<p><img src="https://i.imgur.com/RpD0Iem.png" alt="Timeline" />
The saw tooth pattern continues indefinitely, with the teeth progressively growing slightly larger, but always dropping back down to the same height.
I also checked out the javascript heap snapshot, but it rarely exceeded 10mb, even during peaks.</p>

<p>Based on this, my current theory is that the Graphics.get() method creates excess detached DOM nodes, which build up until garbage collected.  However, I don't know why the spikes get progressively larger, nor do I have any idea as to how to fix it.  If this is a known bug, or common mistake, any further information, solutions, or workarounds would be greatly appreciated.  Thank you again so much for your help!</p>
]]></description>
   </item>
   <item>
      <title>center image rgba array</title>
      <link>https://forum.processing.org/two/discussion/21515/center-image-rgba-array</link>
      <pubDate>Tue, 21 Mar 2017 07:50:00 +0000</pubDate>
      <dc:creator>phantomtnt</dc:creator>
      <guid isPermaLink="false">21515@/two/discussions</guid>
      <description><![CDATA[<p>Hello, i want to work with the pixels of an image that is dinamically centered into the canvas how could i achieve this?</p>

<p>I have this, i've been able to display the pixel array only if the canvas is the same size as the image</p>

<p>`</p>

<pre><code>var wH = window.innerHeight;
var wW = window.innerWidth;
var img;

function preload() {
  img = loadImage('assets/img.png');  
}

function setup() {
  var heigthImg = img.width/img.height*height
  var widthImg = img.height/img.width*width  
  createCanvas(wW, wH);
  background(51); 
  image(img, width/2 - heigthImg/2, 0, heigthImg ,wH);  

  //img.loadPixels();  
}

function draw() {  

//Displays image only if canvas is the same size as the image
//
//  loadPixels();
//   for (var y = 0; y &lt; logoImg.height; y++) {
//    for (var x = 0; x &lt; logoImg.width; x++ ) {
//      //Value index [r, g, b, a] pixel array
//      var pix = (x + y * logoImg.width)*4;
//      var r = logoImg.pixels[pix+0];
//      var g = logoImg.pixels[pix+1];
//      var b = logoImg.pixels[pix+2];
//      var a = logoImg.pixels[pix+3];


//      //set pixels
//      pixels[pix+0] = r;
//      pixels[pix+1] = g;
//      pixels[pix+2] = b;
//      pixels[pix+3] = a;
//    }
//  }
//  updatePixels();
}
</code></pre>

<p>`</p>
]]></description>
   </item>
   </channel>
</rss>